package MiGong;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

class Player {
    private int hp = 100;
    private int attack = 20;
    private int defense = 10;
    private int speed = 80;
    private int invulnerableSteps;
    private int hang;
    private int lie;
    private Weapon currentWeapon;
    private Armor currentArmor;
    private Map<Skill, Integer> skills = new HashMap<>();

    public Player() {
        Skill initialSkill = new Skill("回春手(回复20hp)", "heal", 0, 20, 0, false);
        skills.put(initialSkill, 1);
    }

    public Weapon getCurrentWeapon() {
        return currentWeapon;
    }

    public void setCurrentWeapon(Weapon currentWeapon) {
        this.currentWeapon = currentWeapon;
    }

    public Armor getCurrentArmor() {
        return currentArmor;
    }

    public void setCurrentArmor(Armor currentArmor) {
        this.currentArmor = currentArmor;
    }

    public int getHp() {
        return hp;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void setHp(int hp) {
        this.hp = Math.max(hp, 0);
    }

    public int getAttack() {
        return attack;
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public int getDefense() {
        return defense;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }

    public int getInvulnerableSteps() {
        return invulnerableSteps;
    }

    public void setInvulnerableSteps(int invulnerableSteps) {
        this.invulnerableSteps = invulnerableSteps;
    }

    public void decreaseInvulnerableSteps() {
        if (invulnerableSteps > 0) {
            invulnerableSteps--;
        }
    }

    public void setHang(int hang) {
        this.hang = hang;
    }

    public void setLie(int lie) {
        this.lie = lie;
    }

    public List<Skill> getSkills() {
        return new ArrayList<>(skills.keySet());
    }

    public void addSkill(Skill skill) {
        skills.put(skill, skills.getOrDefault(skill, 0) + 1);
        System.out.println("学会了新技能: " + skill.getName());
    }

    public int getSkillCount(Skill skill) {
        return skills.getOrDefault(skill, 0);
    }

    public void removeSkill(Skill skill) {
        if (skills.containsKey(skill)) {
            if (skills.get(skill) > 1) {
                skills.put(skill, skills.get(skill) - 1);
            } else {
                skills.remove(skill);
            }
        }
    }

    public void useSkill(Skill skill, Monster monster) {
        switch (skill.getEffectType()) {
            case "attack":
                System.out.println("使用技能 " + skill.getName() + "，造成 " + skill.getDamage() + " 伤害");
                break;
            case "heal":
                this.hp = Math.min(this.hp + skill.getHealAmount(), 100);
                System.out.println("使用技能 " + skill.getName() + "，恢复 " + skill.getHealAmount() + " 生命值");
                break;
            case "damageReduction":
                System.out.println("使用技能 " + skill.getName() + "，本次战斗受到的伤害减少 " + (skill.getDamageReduction() * 100) + "%");
                break;
            case "escape":
                break;
        }
    }
}